package cn;

import java.util.Arrays;
import java.util.Random;

public class Count {
	int[] arr() {
		Random r = new Random();
		System.out.println("随机生成10个10-50之间的数：");
		int[] arr = new int[10];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = r.nextInt(41) + 10;
			for (int j = 0; j < i; j++) {
				if (arr[i] == arr[j]) {
					i--;
				}
			}

		}
		System.out.println(Arrays.toString(arr));
		return arr;
	}

	// 判断数组是否存在
	boolean iscz(int[] arr) {
		boolean flag = true;
		int[] newArr = new int[arr.length];
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] > 0) {
				newArr[i] = arr[i];
				flag = true;
			}
		}
		return flag ? true : false;

	}

	// 对数组进行排序
	int[] sort(int[] arr) {
		for (int i = 0; i < arr.length - 1; i++) {
			for (int j = i + 1; j < arr.length; j++) {
				if (arr[i] > arr[j]) {
					int temp = arr[j];
					arr[j] = arr[i];
					arr[i] = temp;
				}

			}
		}

		return arr;
	}

	// 输出数组
	void outPut(int[] arr) {
		System.out.println("输出新数组：");
		System.out.println(Arrays.toString(arr));
	}

	public static void main(String[] args) {
		Count c = new Count();
		int[] arr = c.arr();
		int[] newArr = c.sort(arr);
		boolean arr1 = c.iscz(newArr);
		c.outPut(newArr);
	}

}
